<template>
	<view class="container">
		
		<view  class=" h-46 flex   f-j-s"  style="flex-shrink:initial ;box-sizing:content-box	" >
			<view @click="goBackWithUpdate" class="flex f-a-c f-s-0 padding-lr10 van-icon van-icon-arrow-left f20-size"></view>
		
		
						<view class="flex f-a-c f-s-0 p<strong></strong>adding-lr10 f20-size">店铺分类</view>
						<view class="flex   " >
						
							<!-- <text  @click="go('/pages/search/list?shopId='+id)" class="flex f-s-0 f-a-c padding-lr6 van-icon van-icon-search f20-size"></text> -->
							<!-- <view @tap.stop="toshare"  class="flex f-a-c f-j-c padding-lr5 van-icon van-icon-share-o f20-size"></view> -->
						<!-- 	<view @click="$refs.menuBtn.open()" class="flex f-s-0 f-a-c padding-lr10 van-icon van-icon-weapp-nav f20-size" style="position:relative">
								<text v-if="chatLen > 0"
										class="flex f-a-c f-j-c box-b f11-size t-color-w bg-color-r wrap-len b-radius padding-lr2 "
									style="font-size: 9px; min-width: 16px; height: 16px; position: absolute; top: 5%; left: 20%; white-space: nowrap;">{{chatLen}}</text>
							</view> -->
						</view>
		
						<!-- #ifdef MP-WEIXIN -->
							<xcx-header></xcx-header>
						<!-- #endif -->
				
			
		</view>
		
		<view class="storeClassContent">
			<view class="storeClassContent_item" v-for="(item, index) in storeClassList" :key="index" @tap="go('/pages/product/shopcateAdmin/addShopcate?id='+item.id)">
				<view class="storeClassContent_item_father" @longtap.stop="deleteItem(item,index)">
					<view class="storeClassContent_item_father_label">
						<button class="iconfont" :class="selectStoreClassId == item.store_category_id ? 'icon-jian' : 'icon-tianjia1'"></button>
						<span>{{ item.name }}</span>
					</view>
					<view class="storeClassContent_item_father_right">
						<span class="iconfont icon-bianji" @click.stop="edit(item)"></span>
					</view>
				</view>
				<view class="storeClassContent_item_child" v-if="selectStoreClassId == item.store_category_id">
					<view class="storeClassContent_item_child_item" v-for="(val, i) in item.children" :key="i" @longtap="deleteItem(val,i)">
						<span>{{ val.name }}</span>
						<span class="iconfont icon-bianji" @click.stop="edit(val)"></span>
					</view>
				</view>
			</view>

			<view class="storeClassContent_tip">
				<text class="iconfont icon-duoshanghupc-shuomingdanchuang"></text>
				<span>长按分类标题可删除</span>
			</view>
		</view>
		<view class="handle_bottom"><navigator :url="`/pages/product/shopcateAdmin/addShopcate?mer_id=${mer_id}`" class="handle_bottom_button">添加分类</navigator></view>
	</view>
</template>

<script>
const $ = require('@/utils/api.js');
import { Modal, Toast } from '@/utils/libs/uniApi.js';

import { shopCateList, shopCateDel } from "@/utils/api/admin";
export default {
	data() {
		return {
			selectStoreClassId: 1,
			mer_id: '',
			storeClassList: []
		};
	},
	onLoad(options) {
		this.mer_id = options.mer_id
		this.getshopcateAdmin()
	},
	onShow: function() {

	},
	methods: {
		goBackWithUpdate() {
		      // 设置标识，并返回上一页
		      getCurrentPages().slice(-2)[0].$vm.isUpdateData = true;
		      uni.navigateBack();
		},
		deleteItem(item,index) {
			let that = this
			Modal('温馨提示', `"${item.name}"将被删除，请问是否继续`).then(() => {
				console.log(item);
				shopCateDel(item.id).then(res => {
					that.Tips({
						title: res.message,
						icon: 'success'
					});
					that.getshopcateAdmin()
				}).catch(res => {
					return that.Tips({
						title: res
					});
					uni.redirectTo({
						url: "/pages/product/shopcateAdmin/index"
					})
				});
				// Toast('删除成功');
			})
		},
		selectStoreClass(item) {
			if (item.id == this.selectStoreClassId) {
				this.selectStoreClassId = '';
				return;
			}
			this.selectStoreClassId = item.id;
		},
		/*获取店铺分类*/
		getshopcateAdmin(){
			var that = this;
			uni.showLoading({
				title: '加载中',
				mask: true
			});
			shopCateList().then(
			  res => {
				uni.hideLoading();
			    that.storeClassList = res.data;
			  },
			  error => {
			    that.Tips({
			      title: error.msg
			    })
			  }
			);
		},
		/*编辑*/
		edit(item){
			uni.navigateTo({
				url: `/pages/product/shopcateAdmin/addShopcate?mer_id=${this.mer_id}&pid=${item.store_category_id}`
			})
		}
	}
};
</script>

<style lang="scss" scoped>
@import './scss/index.scss';
</style>
